package cn.itsource.web.controller;

import cn.itsource.doc.CourseDoc;
import cn.itsource.hrm.query.CourseQuery;
import cn.itsource.hrm.utils.AjaxResult;
import cn.itsource.hrm.utils.PageList;
import cn.itsource.repository.CourseElasticsearchRepository;
import cn.itsource.service.ESservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ESController {

    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository;

    @Autowired
    private ESservice eSservice;
    //课程上线
    @RequestMapping(value = "/es/onIineCourse",method = RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc courseDoc){
        //保存方法
        courseElasticsearchRepository.save(courseDoc);
        return AjaxResult.me();
    }

    //课程下线
    @RequestMapping(value = "/es/offLineCourse",method = RequestMethod.POST)
    public AjaxResult offLineCourse(@RequestBody Long id){
        //删除方法
        courseElasticsearchRepository.deleteById(id);
        return AjaxResult.me();
    }

    //查询课程
    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public PageList<CourseDoc> searchCourse(@RequestBody CourseQuery courseQuery){

        return eSservice.searchCourse(courseQuery);
    }
}
